package com.jxbeidou.login.listener;

import com.jxbeidou.core.entity.SecurityUserVO;
import com.jxbeidou.login.event.LoginFailedEvent;
import com.jxbeidou.login.event.LoginSuccessEvent;
import com.jxbeidou.login.event.LogoutSuccessEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;

/**
 * @program: jxbeidou-basic
 * @ClassName: LoginListenerUtil
 * @description: 发布事件
 * @author: 杜晓祥
 * @create: 2023-12-26 17:12
 * 版权所有：交信北斗(北京)信息科技有些公司
 */
@Component
public class LoginListenerUtil {

    @Resource
    private ApplicationEventPublisher applicationEventPublisher;

    public void loginSuccess (SecurityUserVO user, String ip) {
        applicationEventPublisher.publishEvent(new LoginSuccessEvent(user, ip));
    }

    public void loginFailed (SecurityUserVO user, String ip) {
        applicationEventPublisher.publishEvent(new LoginFailedEvent(user, ip));
    }

    public void logoutSuccess (SecurityUserVO user, String ip) {
        applicationEventPublisher.publishEvent(new LogoutSuccessEvent(user, ip));
    }

}
